package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.PlanDetailActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.Models.Plan;
import com.lzw.bluetoothpractice.R;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecoveryAction2ListAdapter extends RecyclerView.Adapter<RecoveryAction2ListAdapter.ViewHolder> {

    private List<Plan> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<Plan> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }
    public RecoveryAction2ListAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        TextView name;
        TextView detail;
        TextView content;
        ImageView pic;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view=itemView;

            name=view.findViewById(R.id.name);
            detail=view.findViewById(R.id.detail);
            content=view.findViewById(R.id.content);
            pic=view.findViewById(R.id.pic);


        }
    }


    @Override
    public int getItemCount() {
        return datas.size();
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        // Glide.with(mcontext).load(sendMessage.getReceptUserHead()).into(holder.iv_head);
        Plan plan = datas.get(position);
        if (holder instanceof RecoveryAction2ListAdapter.ViewHolder) {
            ((ViewHolder) holder).name.setText(plan.getName());

            ((ViewHolder) holder).detail.setText(plan.getDescri());
           // ((ViewHolder) holder).content.setText(Html.fromHtml(plan.getContent()));
            Glide.with(mcontext).load(AppConfig.BASE_URL+plan.getPic()).into(holder.pic);

        }
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mcontext, PlanDetailActivity.class);
                intent.putExtra("planId",plan.getPlanId()+"");

                mcontext.startActivity(intent);
            }
        });
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.item_plan2,parent,false);
        return new ViewHolder(itemView);
    }
}
